package Day08.RPCDemo01.src.cn.tedu.test;

import java.io.*;

class Person implements Serializable {
    private String name;
    private int age;

    public Person(String name, int age){
        this.name = name;
        this.age = age;
    }

    public void eat(){
        System.out.println(this.name+"#eat");
    }

    public void say(){
        System.out.println(this.name+"#say");
    }
}

public class Demo01 {
    public static void main(String[] args) throws Exception {
        Person p1 = new Person("zs",18);
        System.out.println(p1);
        //序列化
        FileOutputStream fout = new FileOutputStream("D:\\person.obj");
        ObjectOutputStream out = new ObjectOutputStream(fout);
        out.writeObject(p1);
        out.flush();
        out.close();

        //反序列化
        FileInputStream fin = new FileInputStream("D:\\person.obj");
        ObjectInputStream in = new ObjectInputStream(fin);
        Person p2 = (Person)in.readObject();
        p2.eat();
        p2.say();
        System.out.println(p2);
    }
}
